package org.demo.quartz;

import org.demo.quartz.listener.TestJobListener;
import org.demo.quartz.listener.TestSchedulerListener;
import org.demo.quartz.listener.TestTriggerListener;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.sql.DataSource;

@Configuration
public class QuartzConfiguration {

    @Bean
    public SchedulerFactoryBean quartzScheduler(DataSource dataSource){
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setDataSource(dataSource);
        schedulerFactoryBean.setSchedulerListeners(new TestSchedulerListener());
        schedulerFactoryBean.setGlobalJobListeners(new TestJobListener());
        schedulerFactoryBean.setGlobalTriggerListeners(new TestTriggerListener());
        return schedulerFactoryBean;
    }

}
